<template>
  <div>
    <div slot="header" class="clearfix">
      <span style="float: left; padding: 3px 0">主机序列号 {{serialnumber}}</span>
      <div style="float: right;">
        <el-upload class="upload-demo" action="#" :show-file-list="false" :on-change="handleChange"
          :file-list="fileList" :auto-upload="false">
          <el-button type="text" icon="el-icon-edit-outline">导入</el-button>
        </el-upload>

      </div>
    </div>
    <com-table :tableData="tableData" url="" keyName="app" :has-data="hasData" :table-head-list="tableHeadList"
      :total-count="totalCount" :page-num="pageNum" :page-size="pageSize" :page-sizes="pageSizes"
      :table-loading="loading" :table-height="tableHeight" :is-show-select="true" :page-show="true" :handle-show="false"
      @setSearchHeight="setTableHeight" ref="comTable">
    </com-table>
  </div>
</template>

<script>
import ComTable from "../../components/table/comTable";
export default {
  components: {
    ComTable,
  },
  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      pageSizes: [5, 10, 20, 100],
      totalCount: 0,
      tableData: [], // 表格数据
      tableHeight: "", // 表格高度
      hasData: true,
      loading: false, // 数据加载状态遮罩
      tableHeadList: [
        { columnComment: "授权类型", columnName: "name", colDisabled: false, colHidden: false, colSearch: true, colSort: false, },
        { columnComment: "授权用户单位名称", columnName: "name", colDisabled: false, colHidden: false, colSearch: true, colSort: false, },
        { columnComment: "主机序列号", olumnName: "state", colDisabled: false, colHidden: false, colSearch: true, colSort: false, },
        { columnComment: "授权时间", columnName: "creator", colDisabled: false, colHidden: false, colSearch: true, colSort: false, },
      ],
      serialnumber: '',
      fileList: [],
      operatingSystem:sessionStorage.getItem('operatingSystem')
    }
  },
  created() {
    this.setTableHeight()
    // this.getTableData()
  },
  methods: {
    setTableHeight() {
      let clientHeiht =
        window.innerHeight || document.documentElement.clientHeight;
      this.tableHeight = clientHeiht - 220;
    },
    getTableData() {
      this.$get('vgmp/config/getserialnumber').then(res => {
        let { data, result } = res.data
        // if (!result) {
        //   return false
        // }
        // console.log(data);
        this.serialnumber = data.data
      })
    },
    search() {
      this.getTableData()
    },
    handleChange(file, fileList) {
      console.log(file);
      this.fileList = [file]
      let str;
      if (this.operatingSystem == 'Windows') {
        str = file.raw.path.lastIndexOf('\\')
      } else {
        str = file.raw.path.lastIndexOf('/')
      }
      let msgFile = file.raw.path.slice(0, str)
      let param = {
        data: {
          method: 'licenseAuthorized',
          reqId: '17ea58c0-1753-4c5e-a6b5-48407908fc83',
          msg: msgFile
        }
      }
      this.$postForJson('vgmp/config/checkauthorization', param).then(res => {
        let data = res.data.data;
        if (!data.result) {
          this.$message.error('导入失败')
          return false
        }
        this.$message.success('导入成功！')
      })
    },
  }
}
</script>

<style>
</style>